package cn.wolfcode.luowowo.service.impl;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.query.DestinationQueryObject;
import cn.wolfcode.luowowo.repository.DestinationRepository;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.util.DBHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DestinationServiceImpl implements IDestinationService{

    @Autowired
    private DestinationRepository destinationRepository;

    @Autowired
    private MongoTemplate template;


    @Override
    public Page<Destination> query(DestinationQueryObject qo) {
        Query query = new Query();
        return DBHelper.query(template,Destination.class,query,qo.getPageable());
    }

    @Override
    public Destination findById(String rid) {
        return destinationRepository.findById(rid).orElse(null);
    }

    @Override
    public List<Destination> list() {
        return destinationRepository.findAll();
    }
}
